﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LibraryMusicStore;
using Microsoft.Practices.Unity;


namespace MvcMusicStore.Models
{
    public class Repository:IRepository
    {
        [Dependency]
        public MusicStoreEntities DB { get; set; }

        public Repository()
        {
            DB = new MusicStoreEntities();
        }

        #region Users
        public User ValidateUser(string loginName, string password)
        {
            return DB.Users.FirstOrDefault(u =>
            u.username == loginName &&
            u.password == password);
        
        }

        public User FindUserByID(int userID)
        {
            return DB.Users.FirstOrDefault(u => u.userid == userID);
            
        }

        public User FindUserByLoginName(string loginName)
        {
            return DB.Users.FirstOrDefault(u => u.username == loginName);
            
        }

        //public User FindUserByOpenID(string openID)
        //{
        //    return DB.Users.FirstOrDefault(u => u.OpenID == openID);
        //}

        public void AddUser(User user)
        {
            DB.Users.InsertOnSubmit(user);
            
        }

        public void CommitChanges()
        {
            DB.SubmitChanges();
            
        }

        //public User GetBlogOwner()
        //{
        //    return DB.User.FirstOrDefault(u => u.IsOwner);
        //}
        #endregion
    }
}
